using UnityEngine;
using UnityEngine.UI;

namespace XProject
{
    public class ProgressWindow : MonoBehaviour
    {

        private Slider m_progressBar;
        private Text m_text;
        private Button m_closeBtn;

        private bool m_isShow = false;


        void Awake()
        {
            InitComp();
            m_closeBtn.onClick.AddListener(Hide);
        }

        private void InitComp()
        {
            m_progressBar = transform.Find("ProgressBar").GetComponent<Slider>();
            m_text = transform.Find("TextBg/ScrollView/Viewport/Text").GetComponent<Text>();
            m_closeBtn = transform.Find("UCloseBtn").GetComponent<Button>();
        }

        public void UpdateprogressBar(int cur, int max)
        {
            if (!m_isShow)
            {
                return;
            }
            m_progressBar.maxValue = max;
            m_progressBar.value = cur;
        }

        public void UpdateMsg(string str)
        {
            if (!m_isShow)
            {
                return;
            }
            m_text.text = str;
        }

        public void ResetProgress()
        {
            UpdateprogressBar(0, 0);
        }

        public void Hide()
        {
            m_isShow = false;
            transform.localPosition = new Vector2(50000, 50000);
        }

        public void Show()
        {
            m_isShow = true;
            transform.localPosition = Vector2.zero;
            ResetProgress();
            HideCloseBtn();
        }

        public void ShowCloseBtn()
        {
            m_closeBtn.gameObject.SetActive(true);

        }

        public void HideCloseBtn()
        {
            m_closeBtn.gameObject.SetActive(false);
        }
    }
}